package gui.newQuiz;

import gui.GUIMain;

import java.awt.FlowLayout;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;

import quiz.QuestionTypes;
import quiz.SimpleQuiz;

public class QuestionWindow extends JFrame {
	private static final long serialVersionUID = -4799141441747131550L;
	JList questionTypes;
	JList selectedQuestions;
	JButton addSelectedQuestionType;
	JButton okButton;
	DefaultListModel listForQuestionTypes;
	DefaultListModel listSelectedQuestions;
	QuestionWindowListener questionListener;
	SimpleQuiz quiz;
	
	public QuestionWindow(SimpleQuiz quiz) {
		this.quiz = quiz;
		initializeVariables();
		setupWindows();
		connectComponents();
		addActionListeners();
	}

	private void initializeVariables() {
		listForQuestionTypes = new DefaultListModel();
		
		for(String questionType : QuestionTypes.getQuestionTypes()) {
			listForQuestionTypes.addElement(questionType);
		}
		
		questionTypes = new JList(listForQuestionTypes);
		
		addSelectedQuestionType = new JButton("Add");
		okButton = new JButton("Ok");
		
		listSelectedQuestions = new DefaultListModel();
		selectedQuestions = new JList(listSelectedQuestions);
		
		questionListener = new QuestionWindowListener(this);
	}

	private void setupWindows() {
		getContentPane().setVisible(true);
	}

	private void connectComponents() {
		getContentPane().setLayout(new FlowLayout());
		getContentPane().add(questionTypes);
		getContentPane().add(addSelectedQuestionType);
		getContentPane().add(selectedQuestions);
		getContentPane().add(okButton);
		
		pack();
	}

	private void addActionListeners() {
		questionTypes.addListSelectionListener(questionListener);
		addSelectedQuestionType.addActionListener(questionListener);
		okButton.addActionListener(questionListener);
	}

}
